package com.caisejingyu.whales.control.widget;

import android.content.Context;
import android.support.v7.widget.AppCompatEditText;
import android.util.AttributeSet;
import android.view.KeyEvent;

import com.caisejingyu.whales.common.base.IKeyEventInterceptor;
import com.caisejingyu.whales.mediator.main.service.MediatorServiceFactory;


/**
 * 键盘拦截EditText
 *
 * @author qinglinyi
 * @date 2018/4/18
 */
public class KeyEventInterceptorEditText extends AppCompatEditText {

    public KeyEventInterceptorEditText(Context context) {
        super(context);
    }

    public KeyEventInterceptorEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public KeyEventInterceptorEditText(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean dispatchKeyEventPreIme(KeyEvent event) {
        IKeyEventInterceptor interceptor = MediatorServiceFactory.getInstance().get(IKeyEventInterceptor.class);
        return (interceptor != null && interceptor.intercept(event)) || super.dispatchKeyEventPreIme(event);
    }
}
